package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.DigitalCollection;
import com.sc.nft.entity.vo.DestroyPrivilegeRuleVO;
import com.sc.nft.entity.vo.PrivilegeRuleVO;
import com.sc.nft.entity.vo.ProductRuleConsensusVO;
import com.sc.nft.entity.vo.ProductRuleVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.PrivilegeRule;
import com.sc.nft.mapper.PrivilegeRuleMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_privilege_rule)数据DAO
 *
 * @author rdg
 * @since 2022-06-28 16:01:14
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class PrivilegeRuleDao extends ServiceImpl<PrivilegeRuleMapper, PrivilegeRule> {

    public List<PrivilegeRuleVO> getByProductId(Long id) {
        return baseMapper.getByProductId(id);
    }

    public Page<ProductRuleVO> getProductRule(int pageNo, int pageSize, Long productId) {
        return baseMapper.getProductRule(new Page(pageNo,pageSize),productId);
    }

    public List<DestroyPrivilegeRuleVO> getByProductIdAndDestory(Long productId, Boolean isDestory) {
        return baseMapper.getByProductIdAndDestory(productId,isDestory);
    }

    public List<PrivilegeRule> getByProductIdAndConsumeId(Long productId, Long consumeCollectionId) {
        LambdaQueryWrapper<PrivilegeRule> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(PrivilegeRule::getProductId,productId);
        wrapper.eq(PrivilegeRule::getConsumeCollectionId,consumeCollectionId);
        return list(wrapper);
    }

    public List<PrivilegeRule> getRuleByProductId(Long productId) {
        LambdaQueryWrapper<PrivilegeRule> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(PrivilegeRule::getProductId,productId);
        return list(wrapper);
    }

    public ProductRuleConsensusVO getCollectionRuleConsensus(Long productId) {
        return baseMapper.getCollectionRuleConsensus(productId);
    }

    public void saveCollectionRuleConsensus(Long productId, Boolean consumeConsensus) {
        LambdaUpdateWrapper<PrivilegeRule> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PrivilegeRule::getProductId,productId);
        updateWrapper.set(PrivilegeRule::getConsumeConsensus,consumeConsensus);
        update(updateWrapper);
    }
}